package com.wutianyi;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wutianyi.jackson.User;

public class Favorites
{
    private Map<TypeReference<?>, Object> favorites = new HashMap<TypeReference<?>, Object>();

    public <T> void setFavorite(TypeReference<T> klass, T thing)
    {
        favorites.put(klass, thing);
    }

    public <T> T getFavorite(TypeReference<T> klass)
    {
        return (T) favorites.get(klass);
    }

    public static void main(String[] args) throws IllegalArgumentException, InstantiationException,
            IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException
    {
        Favorites f = new Favorites();
        f.setFavorite(new TypeReference<String>()
        {
        }, "Java");
        f.setFavorite(new TypeReference<Integer>()
        {
        }, 12);

        ArrayList<String> list = new TypeReference<ArrayList<String>>()
        {
        }.newInstance();
        list.add("String");
        f.setFavorite(new TypeReference<ArrayList<String>>()
        {
        }, list);
        // f.setFavorite(TypeReference<HashMap<String, User>>.class, )
        String s = f.getFavorite(new TypeReference<String>()
        {
        });
        System.out.println(s);
        int i = f.getFavorite(new TypeReference<Integer>()
        {
        });
        System.out.println(i);
        List<String> ll = f.getFavorite(new TypeReference<ArrayList<String>>()
        {
        });
        System.out.println(ll.get(0));
        

    }
}
